import axios from "axios"
import { ElMessage } from 'element-plus'
import {loginout} from "@/comon"
const instance = axios.create({
    baseURL:"http://xue.cnkdl.cn:9082/mall-admin/",
    timeout:5000
})
// 请求拦截器
instance.interceptors.request.use((config)=>{
    console.log("请求拦截器");
    let token = localStorage.getItem("token")
    if(token){
        if(config.headers){
            config.headers["Authorization"] = token
        }
    }
    return config
})
// 响应拦截器
instance.interceptors.response.use((response)=>{
    console.log("响应拦截器");
    const res = response.data as Iresponse<any>
    if(res.code == 401){
        loginout(undefined,()=>{
            // 提示
        ElMessage.error(`账号过期,请重新登录!`)
        })
        
    }
    return response.data
})

export default instance